//
//  AjenController.m
//  AjenKit
//
//  Created by Ajen on 2017/8/31.
//  Copyright © 2017年 中国·北京·洵. All rights reserved.
//
//
//                       .::::.
//                     .::::::::.
//                    ::::Ajen:::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                 .::::::::::::.
//                ::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ````              ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
//  [······UIViewController拓展······]
//

#import "AjenController.h"
#import <objc/message.h>

@implementation UIViewController (AjenKit)

//这里面又实现了一次这个函数,Xcode报警告:Category is implementing a method which will also be implemented by its primary class , 意思是这个函数会执行,而原有的控制器里面的这个函数也仍然会执行,不会覆盖.
-(void)viewWillAppear:(BOOL)animated{
    NSLog(@"\n\n📣📣📣📣📣当前展示的控制器名字 : %@\n\n",NSStringFromClass([self class]));
}
-(void)presentController:(UIViewController *)controller{
    [self presentViewController:controller animated:YES completion:nil];
}
-(void)dismissController{
    [self dismissViewControllerAnimated:YES completion:nil];
}

UIBlurEffect * beffect;
UIVisualEffectView * blurView;
UIView * coverView;
-(void)showGaussianBlur{
    //UIBlurEffect模糊从iOS8.0才出现,所以之前的版本用一个普通View代替
    if([UIDevice currentDevice].systemVersion.doubleValue >= 8.0){
        coverView = nil;
        
        beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        blurView = [[UIVisualEffectView alloc]initWithEffect:beffect];
        blurView.alpha = 0.6;
        blurView.frame = kWindow.frame;
        [kWindow addSubview:blurView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [tap addTarget:self action:@selector(hideGaussianBlur)];
        [blurView addGestureRecognizer:tap];
    }else{
        blurView = nil;
        beffect = nil;
        
        coverView = [[UIView alloc] initWithFrame:kWindow.bounds];
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.75;
        [kWindow addSubview:coverView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [tap addTarget:self action:@selector(hideGaussianBlur)];
        [coverView addGestureRecognizer:tap];
    }
}
-(void)hideGaussianBlur{
    if([UIDevice currentDevice].systemVersion.doubleValue >= 8.0){
        [UIView animateWithDuration:0.2 animations:^{
            blurView.alpha = 0;
        } completion:^(BOOL finished) {
            [blurView removeFromSuperview];
            blurView = nil;
            beffect = nil;
        }];
    }else{
        [UIView animateWithDuration:0.2 animations:^{
            coverView.alpha = 0;
        } completion:^(BOOL finished) {
            [coverView removeFromSuperview];
            coverView = nil;
        }];
    }
}
@end
